package com.dg.gaming.client.gui {
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;

    import mx.containers.Canvas;

    public class DGComponent extends Canvas {
        public function DGComponent() {
            super();
        }

        /**
         * Set the controller by adding a DGController which implements a
         * MouseListener, a MouseMotionListener and a KeyListener.
         *
         * @param controller   Specified controller e.g. ChessController
         */
        public function setController(controller:GameController):void {
            //adding mouse events
            this.addEventListener(MouseEvent.CLICK, controller.mouseClicked);
            this.addEventListener(MouseEvent.DOUBLE_CLICK, controller.mouseDBClicked);
            this.addEventListener(MouseEvent.MOUSE_DOWN, controller.mousePressed);
            this.addEventListener(MouseEvent.MOUSE_MOVE, controller.mouseMoved);
            this.addEventListener(MouseEvent.MOUSE_OUT, controller.mouseExited);
            this.addEventListener(MouseEvent.MOUSE_OVER, controller.mouseMoved);
            this.addEventListener(MouseEvent.MOUSE_UP, controller.mouseReleased);
            this.addEventListener(MouseEvent.MOUSE_WHEEL, controller.mouseWheel);
            //adding keyboard events
            this.addEventListener(KeyboardEvent.KEY_DOWN, controller.keyPressed);
            this.addEventListener(KeyboardEvent.KEY_UP, controller.keyReleased);

        }

        public function repaint():void {
            invalidateDisplayList();
        }

    }
}